#include "pascal.h"

PROGRAM Road Safety
' (c) StarSoft 2024 
' Pascalated Boriel ZX BASIC
' Written by David Magalhaes

' Pascalated Sinclair BASIC (c) 1987 by ZarSoft
' Pascalated BASIC Converter (c) 2021 by Zarsoft
' Pascalated Boriel ZX BASIC (c) 2023 by ZarSoft
' ZX BASIC Compiler (c) 2008 by Boriel

'------------------------------------------------------

' CONSTant declarations
CONST BLACK TYPE UBYTE = 0
CONST BLUE TYPE UBYTE = 1
CONST RED TYPE UBYTE = 2
CONST MAGENTA TYPE UBYTE = 3
CONST GREEN TYPE UBYTE = 4
CONST CYAN TYPE UBYTE = 5
CONST YELLOW TYPE UBYTE = 6
CONST WHITE TYPE UBYTE = 7
CONST TRANSPARENT TYPE UBYTE = 8
CONST MaxPlayers TYPE UBYTE = 4
CONST MaxPlayerNameLength TYPE UBYTE = 10
CONST MapPositionLin TYPE UBYTE = 9
CONST MapPositionCol TYPE UBYTE = 0
CONST CharsSprites TYPE UINTEGER = 64600

' VAR - Global variables
VAR Map(100,5) TYPE BYTE ' Map(100,[line,column,actionType,paper,ink])
VAR DicePatterns(6) TYPE STRING
VAR Action(100) TYPE UBYTE ' Action(100)
VAR PlayerNames(5) TYPE STRING
VAR PlayerColors(4) TYPE UBYTE => {TRANSPARENT, CYAN, GREEN, MAGENTA, RED}
VAR PlayerPositions(5) TYPE UBYTE
VAR Screen0(768) TYPE UBYTE AT 64600 
VAR Screen1(768) TYPE UBYTE AT 64600 - 768*1
VAR Screen2(768) TYPE UBYTE AT 64600 - 768*2
VAR Screen3(768) TYPE UBYTE AT 64600 - 768*3
VAR Screen4(768) TYPE UBYTE AT 64600 - 768*4
VAR PlayerSkipTurns(5) TYPE UBYTE
VAR PlayerSingleDie(5) TYPE BOOLEAN
VAR PlayerWaitAll(5) TYPE BOOLEAN
VAR NumPlayers TYPE UBYTE
VAR ComputerPlays TYPE BOOLEAN
VAR TurnPlayer TYPE UBYTE
VAR UseRealDice TYPE BOOLEAN
VAR Die1Value TYPE UBYTE
VAR Die2Value TYPE UBYTE
VAR DiceTotal TYPE UBYTE
VAR TapePosition TYPE UBYTE
VAR UseImages TYPE BOOLEAN

DECLARE PROCEDURE RunAction
DECLARE PROCEDURE RollDice

'--------------------------------------------------------------

PROCEDURE WaitNokey
BEGIN
REPEAT
UNTIL (INKEY = "")
END PROCEDURE

FUNCTION ReadOption TYPE STRING
VAR key$ TYPE STRING
BEGIN
REPEAT
  PAUSE 1
  PAUSE 0
  key$ = INKEY$
  IF key$ = "" THEN key$ = "#"
UNTIL (key$ >= "1" AND key$ <= "4" ) OR (key$ = "9" OR key$ = "0" )
BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
RETURN key$
END FUNCTION

'--------------------------------------------------------------

PROCEDURE EraseSprite(l TYPE UBYTE, c TYPE UBYTE)
BEGIN
PAPER BLACK
PRINT AT l+0,c; "            "
PRINT AT l+1,c; "            "
PRINT AT l+2,c; "            "
PRINT AT l+3,c; "            "
PRINT AT l+4,c; "            "
PRINT AT l+5,c; "            "
PRINT AT l+6,c; "            "
PRINT AT l+7,c; "            "
END PROCEDURE

PROCEDURE ShowSprite(l TYPE UBYTE, c TYPE UBYTE)
BEGIN
POKE 23606,CharsSprites-256*INT (CharsSprites/256)
POKE 23607,INT (CharsSprites/256)-1
PRINT AT l+0,c; " (08@HPX`hpx"
PRINT AT l+1,c; "!)19AIQYaiqy"
PRINT AT l+2,c; """*2:BJRZbjrz"
PRINT AT l+3,c; "#+3;CKS[cks{"
PRINT AT l+4,c; "$,4<DLT\\dlt|"
PRINT AT l+5,c; "%-5=EMU]emu}"
PRINT AT l+6,c; "&.6>FNV^fnv~"
PRINT AT l+7,c; "'/7?GOW_gow\*"
POKE 23606,0
POKE 23607,60
END PROCEDURE

PROCEDURE SaveSprite(player TYPE UBYTE)
BEGIN
IF (UseImages)
  IF (player = 1)
    LET Screen1 = Screen0
  ELSEIF (player = 2)
    LET Screen2 = Screen0
  ELSEIF (player = 3)
    LET Screen3 = Screen0
  ELSEIF (player = 4)
    LET Screen4 = Screen0
  ENDIF
ENDIF
END PROCEDURE

PROCEDURE RestoreSprite
BEGIN
IF (UseImages)
  IF (TurnPlayer = 1)
    LET Screen0 = Screen1
  ELSEIF (TurnPlayer = 2)
    LET Screen0 = Screen2
  ELSEIF (TurnPlayer = 3)
    LET Screen0 = Screen3
  ELSEIF (TurnPlayer = 4)
    LET Screen0 = Screen4
  ENDIF
  PAPER Map(PlayerPositions(TurnPlayer),4)
  INK Map(PlayerPositions(TurnPlayer),5)
  ShowSprite(12,19)
ENDIF
END PROCEDURE

PROCEDURE LoadSprite(square TYPE UBYTE)
IF (UseImages)
  LET TapePosition = square
  'PRINT AT 0,0; PAPER BLACK; INK WHITE; TapePosition; " "
  LOAD STR(square) CODE
  BORDER BLACK
ENDIF
END PROCEDURE

PROCEDURE TapeForward(player TYPE UBYTE)
VAR goal TYPE UBYTE
VAR dist TYPE UBYTE
VAR delay TYPE BYTE
BEGIN
LET delay = 2*50
IF (UseImages)
  LET dist = PlayerPositions(player) - TapePosition
  IF (dist < 0) THEN LET dist = dist + 100
  IF (dist > 25) THEN LET dist = 25
  IF (dist > 0)
    LET goal = (TapePosition + dist) MOD 100
    LoadSprite(goal)
  ENDIF
  LET delay = delay - INT(50*dist/10)
  IF (delay < 1) THEN delay = 1
ENDIF
PAUSE delay
END PROCEDURE

'--------------------------------------------------------------

DATA 0,"Wait, you're still home? Hurry up! Or you'll be late for school!"
DATA 1,"You should already be at school."
DATA 2,"Obligation: Route to be used by pedal cycles only."
DATA 3,"Your neighbor rides a bicycle."
DATA 4,"Information: Gas station ahead."
DATA 5,"Danger: Road with speed bumps."
DATA 6,"You crossed the street on a red light. =You don't play next turn."
DATA 7,"Forbidden: The speed limit is 40 Km/h."
DATA 8,"You see your neighbor riding his scooter."
DATA 9,"Obligation: Pedestrians have to take this road."
DATA 10,"You see your neighbor's dog."
DATA 11,"You see a van passing by."
DATA 12,"Obligation: Turn left."
DATA 13,"The light is red. =Go back to square 7."
DATA 14,"Danger: Loose debris on the road."
DATA 15,"Information: The recommended speed is 60 Km/h."
DATA 16,"Danger: Railroad crossing. You must wait. =You don't play next turn."
DATA 17,"Forbidden: No cycling."
DATA 18,"Danger: Two-way traffic."
DATA 19,"A car passes by."
DATA 20,"Information: First aid station."
DATA 21,"Information: Auto repair shop."
DATA 22,"Danger: Road bends to the right."
DATA 23,"Your guardian angel watches over you. *Move again the same amount."
DATA 24,"Forbidden: No left turn."
DATA 25,"A tanker truck goes to the gas station."
DATA 26,"Information: Gas station ahead."
DATA 27,"Information: Restaurant ahead."
DATA 28,"You tried to enter a moving vehicle. =Go back to square 11."
DATA 29,"Danger: Roadworks ahead."
DATA 30,"You arrived at a church."
DATA 31,"Information: U-turn ahead."
DATA 32,"Information: Dead end."
DATA 33,"Obligation: The minimum speed is 30 Km/h."
DATA 34,"Information: Hospital with emergency service."
DATA 35,"Danger: Unusual danger."
DATA 36,"Obligation: Turn left ahead."
DATA 37,"You see a boy inflating a ball with an air pump."
DATA 38,"You join some boys playing ball on the street. =You don't play the next 2 turns."
DATA 39,"Information: Gas station ahead."
DATA 40,"Well done! You used the crosswalk to cross the street. *You get to play again."
DATA 41,"Danger: Double curve."
DATA 42,"Obligation: Turn left."
DATA 43,"You checked your watch, and realized that school is about to start."
DATA 44,"Forbidden: No vehicles allowed."
DATA 45,"Danger: Road narrows ahead."
DATA 46,"Your guardian angel watches over you. *Move again the same amount."
DATA 47,"You see a boy approaching the school."
DATA 48,"You get into a fight. =Go back to square 1."
DATA 49,"Danger: Children crossing ahead."
DATA 50,"You arrive at school."
DATA 51,"Forbidden: No parking."
DATA 52,"Information: Bus stop."
DATA 53,"A car passes by."
DATA 54,"An ambulance goes to the Hospital."
DATA 55,"Information: Hospital."
DATA 56,"Forbidden: No parking."
DATA 57,"it's an area full of buildings!"
DATA 58,"Obligation: Roundabout."
DATA 59,"Information: Gas station ahead."
DATA 60,"You see a car passing by."
DATA 61,"Obligation: Straight ahead."
DATA 62,"Danger: Crossroad with priority."
DATA 63,"Priority: Give way."
DATA 64,"Danger: Crossroad without priority. =You can only use 1 die next turn."
DATA 65,"Danger: Pedestrians."
DATA 66,"Information: Parking is permitted."
DATA 67,"Forbidden: Overtaking is not allowed."
DATA 68,"Danger: Slippery road."
DATA 69,"Information: Hotel or motel."
DATA 70,"Your guardian angel watches over you. *Move again the same amount."
DATA 71,"Priority: Stop."
DATA 72,"Danger: Crossroad without priority. =You can only use 1 die next turn."
DATA 73,"A truck passes by."
DATA 74,"Forbidden: No standing or parking."
DATA 75,"Information: One way."
DATA 76,"You jumped out of a moving vehicle. =Go back to square 63."
DATA 77,"You check the clock. You must return home in time for dinner."
DATA 78,"Forbidden: No entry."
DATA 79,"You see a Shell tanker truck."
DATA 80,"Forbidden: No U-turns allowed."
DATA 81,"Don't walk in the middle of the street. =Wait for all players to reach you."
DATA 82,"You've stumbled into a cart from a nearby shopping center."
DATA 83,"Look, a shopping center!"
DATA 84,"Well done! You obeyed the policeman. *He rewards you with another dice roll."
DATA 85,"Obligation: Cyclist must use cycle path."
DATA 86,"Look, a dog!"
DATA 87,"You see a bicycle."
DATA 88,"Your guardian angel watches over you. *Move again the same amount."
DATA 89,"A big truck passes by."
DATA 90,"Information: There is an airport nearby."
DATA 91,"Danger: Cattle crossing."
DATA 92,"Information: Camping site."
DATA 93,"Information: Recommended speed is 60 Km/h."
DATA 94,"Well done! You didn't forget to do what your mother asked. *Go forward to square 97."
DATA 95,"You see your neighbor riding his bicycle."
DATA 96,"Obligation: Pedestrians must use this lane."
DATA 97,"Forbidden: No motor vehicles."
DATA 98,"You forgot to do what your mother asked. =Go back to square 92."
DATA 99,"You're almost home."
DATA 100,"Home, sweet home."

'--------------------------------------------------------------

PROCEDURE WriteLine2 (m$ TYPE STRING)
VAR n TYPE INTEGER
'POKE 23692,24 : REM disable scroll message
FOR n=0 TO LEN m$-1
  IF m$(n) <> "*" AND m$(n) <> "=" THEN PRINT m$(n);
  IF m$(n) = "*" THEN INK GREEN
  IF m$(n) = "=" THEN INK MAGENTA
  IF m$(n) = " " THEN BEEP .02,10+10*RND
NEXT n
IF LEN m$ < 32 THEN PRINT
IF m$(0) = "*" AND LEN m$ = 32 THEN PRINT
END PROCEDURE

PROCEDURE WriteLine (m$ TYPE STRING)
VAR n TYPE INTEGER
BEGIN
IF LEN m$ <= 32
  WriteLine2(m$)
ELSE
  n=31
  WHILE m$(n) <> " "
    n = n-1
  END WHILE
  WriteLine2(m$(0 TO n-1))
  WriteLine(m$(n+1 TO))
ENDIF
END PROCEDURE

PROCEDURE WriteDescription
VAR position TYPE UBYTE
VAR i TYPE UBYTE
VAR n TYPE UBYTE
VAR text TYPE STRING
BEGIN
RESTORE
position = PlayerPositions(TurnPlayer)
FOR i = 0 TO position
  READ n, text
NEXT i
PAPER BLACK
INK WHITE
PRINT AT 20,0; " "; TAB 32; " "; TAB 32; " "; TAB 32;
PRINT AT 20,0;
WriteLine(text)
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE PlacePlayer (player TYPE UBYTE)
VAR position TYPE UBYTE
VAR color TYPE UBYTE
VAR l TYPE UBYTE
VAR c TYPE UBYTE
BEGIN
LET position = PlayerPositions(player)
LET color = PlayerColors(player)
LET l = MapPositionLin + Map(position, 1)
LET c = MapPositionCol + Map(position, 2)
PRINT AT l, c; OVER 1; PAPER color; INK TRANSPARENT; " ";
PAPER BLACK
END PROCEDURE

PROCEDURE WritePlayersInfo
VAR position TYPE UBYTE
BEGIN
PAPER BLACK
INK WHITE
PRINT AT 0,19; "PLAYERS:"
FOR i = 1 TO NumPlayers
  LET position = PlayerPositions(i)
  INK(PlayerColors(i))
  IF (i = TurnPlayer) THEN FLASH 1
  PRINT AT 1+i,19; (PlayerNames(i) + "..........")(0 TO MaxPlayerNameLength-1); FLASH 0; position;
  FLASH 0
  IF position < 10 THEN PRINT " "
NEXT i
PRINT 
END PROCEDURE

PROCEDURE PlacePlayers
VAR i TYPE UBYTE
VAR p TYPE UBYTE
BEGIN
WritePlayersInfo
LET p = TurnPlayer-1
IF (p = 0) THEN p = NumPlayers
FOR i = 1 TO NumPlayers-1
  PlacePlayer(p)
  LET p = p-1
  IF (p = 0) THEN p = NumPlayers
NEXT i
FLASH 1
PlacePlayer(TurnPlayer)
FLASH 0
END PROCEDURE

PROCEDURE RemovePlayer (player TYPE UBYTE)
VAR position TYPE UBYTE
VAR color TYPE UBYTE
VAR l TYPE UBYTE
VAR c TYPE UBYTE
BEGIN
LET position = PlayerPositions(player)
LET l = MapPositionLin + Map(position, 1)
LET c = MapPositionCol + Map(position, 2)
LET color = WHITE - position MOD 2
PRINT AT l, c; OVER 1; PAPER color; INK TRANSPARENT; " ";
PAPER BLACK
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE LandOnSquare
PlacePlayers
IF (UseImages) THEN EraseSprite(12,19)
WriteDescription
IF (UseImages)
  LoadSprite(PlayerPositions(TurnPlayer))
  PAPER Map(PlayerPositions(TurnPlayer),4)
  INK Map(PlayerPositions(TurnPlayer),5)
  ShowSprite(12,19)
  SaveSprite(TurnPlayer)
  PAPER BLACK
ENDIF
IF (Map(PlayerPositions(TurnPlayer),3)) THEN RunAction
END PROCEDURE

PROCEDURE MovePlayer
BEGIN
RemovePlayer(TurnPlayer)
LET PlayerPositions(TurnPlayer) = PlayerPositions(TurnPlayer) + DiceTotal
IF (PlayerPositions(TurnPlayer) > 100) THEN PlayerPositions(TurnPlayer) = 100
LandOnSquare
END PROCEDURE

PROCEDURE MoveToSquare (square TYPE INTEGER)
RemovePlayer(TurnPlayer)
LET PlayerPositions(TurnPlayer) = square
LandOnSquare
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE RunAction
VAR square TYPE INTEGER
BEGIN
PRINT AT 23,0; INK YELLOW; "Press any key to continue"; TAB 32;
PAUSE 5*50
PRINT AT 23,0; " "; TAB 32;
LET square = PlayerPositions(TurnPlayer)
IF square = 6 OR square = 16
  LET PlayerSkipTurns(TurnPlayer) = 1
ELSEIF square = 13
  MoveToSquare(7)
ELSEIF square = 23 OR square = 46 OR square = 70 OR square = 88
  MovePlayer
ELSEIF square = 28
  MoveToSquare(11)
ELSEIF square = 38
  LET PlayerSkipTurns(TurnPlayer) = 2
ELSEIF square = 40 OR square = 84
  RollDice
  MovePlayer
ELSEIF square = 48
  MoveToSquare(1)
ELSEIF square = 64 OR square = 72
  PlayerSingleDie(TurnPlayer) = TRUE
ELSEIF square = 76
  MoveToSquare(63)
ELSEIF square = 81
  LET PlayerWaitAll(TurnPlayer) = TRUE
ELSEIF square = 94
  MoveToSquare(97)
ELSEIF square = 98
  MoveToSquare(92)
ENDIF
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE PrintDie (lin TYPE UBYTE, col TYPE UBYTE, value TYPE UBYTE)
BEGIN
PAPER WHITE : INK BLACK
PRINT AT lin,col; DicePatterns(value)(0 TO 2)
PRINT AT lin+1,col; DicePatterns(value)(3 TO 5)
PRINT AT lin+2,col; DicePatterns(value)(6 TO 8)
PAPER BLACK
END PROCEDURE

PROCEDURE PrintDice
BEGIN
PrintDie(8, 21, Die1Value)
PrintDie(8, 26, Die2Value)
END PROCEDURE

PROCEDURE EraseDice
BEGIN
LET Die1Value = 0
LET Die2Value = 0
LET DiceTotal = 0
PrintDice
END PROCEDURE

PROCEDURE RollComputerDice
BEGIN
TapeForward(TurnPlayer)
PRINT AT 23,0; INK YELLOW; "The computer rolls the dice"; TAB 32;
TapeForward(TurnPlayer)
RANDOMIZE
Die1Value = 1 + INT(RND*6)
IF (PlayerSingleDie(TurnPlayer))
  PlayerSingleDie(TurnPlayer) = FALSE
ELSE
  Die2Value = 1 + INT(RND*6)
ENDIF
DiceTotal = Die1Value + Die2Value
PRINT AT 23,0; " "; TAB 32;
END PROCEDURE

PROCEDURE RollVirtualDice
BEGIN
TapeForward(TurnPlayer)
PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); ", press R to roll dice"; TAB 32;
REPEAT
  PAUSE 0
UNTIL INKEY = "r"
BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
PRINT AT 23,0; INK YELLOW; "Rolling dice..."; TAB 32;
TapeForward(TurnPlayer)
RANDOMIZE
Die1Value = 1 + INT(RND*6)
IF (PlayerSingleDie(TurnPlayer))
  PlayerSingleDie(TurnPlayer) = FALSE
ELSE
  Die2Value = 1 + INT(RND*6)
ENDIF
DiceTotal = Die1Value + Die2Value
PRINT AT 23,0; " "; TAB 32;
END PROCEDURE

PROCEDURE RollRealDice
VAR key TYPE STRING
BEGIN
TapeForward(TurnPlayer)
PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); ", insert die 1 value"; TAB 32;
REPEAT
  PAUSE 0
  LET key = INKEY
UNTIL key >= "1" AND key <= "6"
BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
PRINT AT 23,0; " "; TAB 32;
Die1Value = VAL(key)
PrintDice
TapeForward(TurnPlayer)
WaitNokey
IF (PlayerSingleDie(TurnPlayer))
  PlayerSingleDie(TurnPlayer) = FALSE
ELSE
  PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); ", insert die 2 value"; TAB 32;
  REPEAT
    PAUSE 0
    LET key = INKEY
  UNTIL key >= "1" AND key <= "6"
  BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
  PRINT AT 23,0; " "; TAB 32;
  Die2Value = VAL(key)
ENDIF
DiceTotal = Die1Value + Die2Value
END PROCEDURE

PROCEDURE RollDice
BEGIN
EraseDice
IF (ComputerPlays AND TurnPlayer = 2)
  RollComputerDice
ELSEIF (UseRealDice)
  RollRealDice
ELSE
  RollVirtualDice
ENDIF
PrintDice
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE DefineRoofLeft
BEGIN
POKE USR "U"+0, BIN 00000000
POKE USR "U"+1, BIN 00000000
POKE USR "U"+2, BIN 00000000
POKE USR "U"+3, BIN 00000000
POKE USR "U"+4, BIN 00000011
POKE USR "U"+5, BIN 00001111
POKE USR "U"+6, BIN 00111111
POKE USR "U"+7, BIN 11111111
END PROCEDURE

PROCEDURE DefineHouseLeft
BEGIN
POKE USR "U"+0, BIN 10000000
POKE USR "U"+1, BIN 10011111
POKE USR "U"+2, BIN 10010101
POKE USR "U"+3, BIN 10010101
POKE USR "U"+4, BIN 10011111
POKE USR "U"+5, BIN 10000000
POKE USR "U"+6, BIN 10000000
POKE USR "U"+7, BIN 10000000
END PROCEDURE

PROCEDURE DefineRoofRight
BEGIN
POKE USR "U"+0, BIN 00000000
POKE USR "U"+1, BIN 00000000
POKE USR "U"+2, BIN 00000000
POKE USR "U"+3, BIN 00000000
POKE USR "U"+4, BIN 11000000
POKE USR "U"+5, BIN 11110000
POKE USR "U"+6, BIN 11111100
POKE USR "U"+7, BIN 11111111
END PROCEDURE

PROCEDURE DefineHouseRight
BEGIN
POKE USR "U"+0, BIN 00000001
POKE USR "U"+1, BIN 01111101
POKE USR "U"+2, BIN 01010101
POKE USR "U"+3, BIN 01010101
POKE USR "U"+4, BIN 01111101
POKE USR "U"+5, BIN 00000001
POKE USR "U"+6, BIN 00000001
POKE USR "U"+7, BIN 00000001
END PROCEDURE

PROCEDURE DefineDoor
BEGIN
POKE USR "U"+0, BIN 00000000
POKE USR "U"+1, BIN 00000000
POKE USR "U"+2, BIN 00111110
POKE USR "U"+3, BIN 00100010
POKE USR "U"+4, BIN 00100010
POKE USR "U"+5, BIN 00100110
POKE USR "U"+6, BIN 00100010
POKE USR "U"+7, BIN 00100010
END PROCEDURE

PROCEDURE DrawHouses
BEGIN
DefineRoofLeft
PAPER BLACK : INK RED
PRINT AT MapPositionLin + Map(0,1)-1, MapPositionCol + Map(0,2)-1; "\U\..";
PAPER BLUE
PRINT AT MapPositionLin + Map(50,1)-1, MapPositionCol + Map(50,2)-1; "\U\..";
DefineHouseLeft
PAPER WHITE : INK BLACK
PRINT AT MapPositionLin + Map(0,1), MapPositionCol + Map(0,2)-1; "\U";
PRINT AT MapPositionLin + Map(50,1), MapPositionCol + Map(50,2)-1; "\U";
DefineRoofRight
PAPER BLACK : INK RED
PRINT AT MapPositionLin + Map(0,1)-1, MapPositionCol + Map(0,2)-1+2; "\U";
PAPER BLUE
PRINT AT MapPositionLin + Map(50,1)-1, MapPositionCol + Map(50,2)-1+2; "\U";
DefineHouseRight
PAPER WHITE : INK BLACK
PRINT AT MapPositionLin + Map(0,1), MapPositionCol + Map(0,2)-1+2; "\U";
PRINT AT MapPositionLin + Map(50,1), MapPositionCol + Map(50,2)-1+2; "\U";
DefineDoor
PAPER WHITE : INK BLACK
PRINT AT MapPositionLin + Map(0,1), MapPositionCol + Map(0,2); "\U";
PRINT AT MapPositionLin + Map(50,1), MapPositionCol + Map(50,2); "\U";
END PROCEDURE

PROCEDURE DrawMap
CONST offset TYPE UBYTE = CODE "\A"
VAR l TYPE UBYTE
VAR c TYPE UBYTE
VAR digit TYPE UBYTE
VAR char TYPE STRING
VAR color TYPE UBYTE
BEGIN
PAPER BLUE
FOR i = MapPositionLin TO MapPositionLin+10
  PRINT AT i,0; " "; TAB Map(88,2)
NEXT i
DrawHouses
FOR i = 1 TO 99
  IF (i <> 50)
    LET l = MapPositionLin + Map(i,1)
    LET c = MapPositionCol + Map(i,2)
    IF (Map(i,3) = -1)
      INK MAGENTA
    ELSEIF (Map(i,3) = 1)
      INK GREEN
    ELSE
      INK BLACK
    ENDIF
    PAPER WHITE - i MOD 2
    LET digit = i MOD 10
    PRINT AT l, c; CHR(offset + digit);
    LET digit = INT(i / 10)
    PRINT AT l, c; OVER 1; CHR(offset + 10 + digit);
  ENDIF
NEXT i
PAPER BLACK
END PROCEDURE

PROCEDURE DrawScreen
VAR i TYPE UBYTE
BEGIN
CLS
WritePlayersInfo
PlacePlayers

PAPER YELLOW
FOR i = 0 TO 7
  PRINT AT i,0; "                 ";
NEXT i

LOAD "shell" CODE
BORDER BLACK
INK RED
ShowSprite(0,0)
PAPER BLACK : INK GREEN
ShowSprite(12,21)

PAPER BLACK
FOR i = 2 TO 5
  PRINT AT i, 8; "        ";
NEXT i
INK GREEN
PRINT AT 3,9; " ROAD "
PRINT AT 4,9; "SAFETY"

DrawMap

PAPER BLACK

LoadSprite(0)
SaveSprite(1)
SaveSprite(2)
SaveSprite(3)
SaveSprite(4)
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE CompactPlayers
VAR i TYPE UBYTE
VAR tail TYPE UBYTE
BEGIN
LET tail = 0
FOR i=1 TO MaxPlayers
  IF (PlayerNames(i)(0) >= "A")
    LET tail = tail + 1
    PlayerNames(tail) = PlayerNames(i)
  ENDIF
NEXT i
FOR i=tail+1 TO MaxPlayers
  PlayerNames(i) = ""
NEXT i
LET NumPlayers = tail
END PROCEDURE

PROCEDURE ConfigPlayers
VAR i TYPE UBYTE
VAR option TYPE UBYTE
BEGIN
BORDER BLACK : PAPER BLACK : INK WHITE : CLS
PRINT AT 0,0;
PRINT "THE SHELL ROAD SAFETY GAME"
PRINT AT 12,0; 
PRINT "9 - play with real dice"
PRINT "0 - play with computer dice"
PRINT AT 21,0; INK YELLOW; "Select an option: 1-4 9 0";
REPEAT
  FOR i = 1 TO MaxPlayers
    INK PlayerColors(i)
    PRINT AT 5+i,0; "Player "; i; " - "; (PlayerNames(i) + "..........")(0 TO MaxPlayerNameLength-1)
  NEXT i
  LET option = VAL(ReadOption)
  IF (option >= 1 AND option <= 4)
    INK PlayerColors(option)
    PRINT AT 5+option,11; "..........";
    PRINT AT 5+option,11;
    LET PlayerNames(option) = INPUT(MaxPlayerNameLength)
    CompactPlayers
  ELSEIF (option = 9)
    LET UseRealDice = TRUE
  ELSEIF (option = 0)
    LET UseRealDice = FALSE
  ENDIF
UNTIL ((option = 9 OR option = 0) AND (PlayerNames(1)(0) >= "A"))
IF (NumPlayers = 1)
  LET ComputerPlays = TRUE
  LET NumPlayers = 2
  PlayerNames(NumPlayers) = "Spectrum"
ENDIF
LET TurnPlayer = NumPlayers ' Will become 1 beginning the first turn 
END PROCEDURE

PROCEDURE InitGame
VAR i TYPE UBYTE
BEGIN
' initialize players
LET ComputerPlays = FALSE
FOR i=0 TO 5
  LET PlayerNames(i) = ""
  LET PlayerPositions(i) = 0
  LET PlayerSkipTurns(i) = 0
  LET PlayerSingleDie(i) = FALSE
  LET PlayerWaitAll(i) = FALSE
NEXT i
LET TurnPlayer = 0
LET NumPlayers = 0
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE InitProgram
BEGIN
BORDER WHITE : PAPER WHITE : INK BLACK
LOAD "screen" CODE : PAUSE 5*50
LOAD "small" CODE
BORDER BLACK
REM Dice Patterns initialization
' DIM DicePatterns(6)
LET DicePatterns(0) = "         "
LET DicePatterns(1) = "    o    "
LET DicePatterns(2) = "o       o"
LET DicePatterns(3) = "o   o   o"
LET DicePatterns(4) = "o o   o o"
LET DicePatterns(5) = "o o o o o"
LET DicePatterns(6) = "o oo oo o"
REM Map initialization
' DIM Map(100, Line+Column)
LET Map(00,1) = 00 : LET Map(00,2) = 03                      : LET Map(00,4) = CYAN    : LET Map(00,5) = BLACK
LET Map(01,1) = 00 : LET Map(01,2) = 01                      : LET Map(01,4) = RED     : LET Map(01,5) = BLACK
LET Map(02,1) = 00 : LET Map(02,2) = 00                      : LET Map(02,4) = WHITE   : LET Map(02,5) = BLUE
LET Map(03,1) = 01 : LET Map(03,2) = 00                      : LET Map(03,4) = GREEN   : LET Map(03,5) = BLACK
LET Map(04,1) = 02 : LET Map(04,2) = 00                      : LET Map(04,4) = WHITE   : LET Map(04,5) = BLUE
LET Map(05,1) = 03 : LET Map(05,2) = 00                      : LET Map(05,4) = WHITE   : LET Map(05,5) = RED
LET Map(06,1) = 04 : LET Map(06,2) = 00 : LET Map(06,3) = -1 : LET Map(06,4) = CYAN    : LET Map(06,5) = RED
LET Map(07,1) = 05 : LET Map(07,2) = 00                      : LET Map(07,4) = WHITE   : LET Map(07,5) = RED
LET Map(08,1) = 06 : LET Map(08,2) = 00                      : LET Map(08,4) = GREEN   : LET Map(08,5) = BLACK
LET Map(09,1) = 07 : LET Map(09,2) = 00                      : LET Map(09,4) = WHITE   : LET Map(09,5) = BLUE
LET Map(10,1) = 08 : LET Map(10,2) = 00                      : LET Map(10,4) = MAGENTA : LET Map(10,5) = YELLOW
LET Map(11,1) = 09 : LET Map(11,2) = 00                      : LET Map(11,4) = CYAN    : LET Map(11,5) = BLACK
LET Map(12,1) = 10 : LET Map(12,2) = 00                      : LET Map(12,4) = WHITE   : LET Map(12,5) = BLUE
LET Map(13,1) = 10 : LET Map(13,2) = 01 : LET Map(13,3) = -1 : LET Map(13,4) = YELLOW  : LET Map(13,5) = RED
LET Map(14,1) = 10 : LET Map(14,2) = 02                      : LET Map(14,4) = WHITE   : LET Map(14,5) = RED
LET Map(15,1) = 09 : LET Map(15,2) = 02                      : LET Map(15,4) = WHITE   : LET Map(15,5) = BLUE
LET Map(16,1) = 08 : LET Map(16,2) = 02 : LET Map(16,3) = -1 : LET Map(16,4) = WHITE   : LET Map(16,5) = RED
LET Map(17,1) = 07 : LET Map(17,2) = 02                      : LET Map(17,4) = WHITE   : LET Map(17,5) = RED
LET Map(18,1) = 06 : LET Map(18,2) = 02                      : LET Map(18,4) = WHITE   : LET Map(18,5) = RED
LET Map(19,1) = 05 : LET Map(19,2) = 02                      : LET Map(19,4) = YELLOW  : LET Map(19,5) = BLUE
LET Map(20,1) = 04 : LET Map(20,2) = 02                      : LET Map(20,4) = WHITE   : LET Map(20,5) = BLUE
LET Map(21,1) = 03 : LET Map(21,2) = 02                      : LET Map(21,4) = WHITE   : LET Map(21,5) = BLUE
LET Map(22,1) = 02 : LET Map(22,2) = 02                      : LET Map(22,4) = WHITE   : LET Map(22,5) = RED
LET Map(23,1) = 02 : LET Map(23,2) = 03 : LET Map(23,3) = 1  : LET Map(23,4) = CYAN    : LET Map(23,5) = WHITE
LET Map(24,1) = 02 : LET Map(24,2) = 04                      : LET Map(24,4) = WHITE   : LET Map(24,5) = RED
LET Map(25,1) = 03 : LET Map(25,2) = 04                      : LET Map(25,4) = BLUE    : LET Map(25,5) = WHITE
LET Map(26,1) = 04 : LET Map(26,2) = 04                      : LET Map(26,4) = WHITE   : LET Map(26,5) = BLUE
LET Map(27,1) = 05 : LET Map(27,2) = 04                      : LET Map(27,4) = WHITE   : LET Map(27,5) = BLUE
LET Map(28,1) = 06 : LET Map(28,2) = 04 : LET Map(28,3) = -1 : LET Map(28,4) = CYAN    : LET Map(28,5) = BLACK
LET Map(29,1) = 07 : LET Map(29,2) = 04                      : LET Map(29,4) = WHITE   : LET Map(29,5) = RED
LET Map(30,1) = 08 : LET Map(30,2) = 04                      : LET Map(30,4) = BLUE    : LET Map(30,5) = WHITE
LET Map(31,1) = 09 : LET Map(31,2) = 04                      : LET Map(31,4) = WHITE   : LET Map(31,5) = BLUE
LET Map(32,1) = 10 : LET Map(32,2) = 04                      : LET Map(32,4) = WHITE   : LET Map(32,5) = BLUE 
LET Map(33,1) = 10 : LET Map(33,2) = 05                      : LET Map(33,4) = WHITE   : LET Map(33,5) = BLUE
LET Map(34,1) = 10 : LET Map(34,2) = 06                      : LET Map(34,4) = WHITE   : LET Map(34,5) = BLUE
LET Map(35,1) = 10 : LET Map(35,2) = 07                      : LET Map(35,4) = WHITE   : LET Map(35,5) = RED
LET Map(36,1) = 10 : LET Map(36,2) = 08                      : LET Map(36,4) = WHITE   : LET Map(36,5) = BLUE
LET Map(37,1) = 09 : LET Map(37,2) = 08                      : LET Map(37,4) = YELLOW  : LET Map(37,5) = BLACK
LET Map(38,1) = 08 : LET Map(38,2) = 08 : LET Map(38,3) = -1 : LET Map(38,4) = YELLOW  : LET Map(38,5) = BLACK
LET Map(39,1) = 07 : LET Map(39,2) = 08                      : LET Map(39,4) = WHITE   : LET Map(39,5) = BLUE
LET Map(40,1) = 06 : LET Map(40,2) = 08 : LET Map(40,3) = 1  : LET Map(40,4) = WHITE   : LET Map(40,5) = BLUE
LET Map(41,1) = 05 : LET Map(41,2) = 08                      : LET Map(41,4) = WHITE   : LET Map(41,5) = RED
LET Map(42,1) = 04 : LET Map(42,2) = 08                      : LET Map(42,4) = WHITE   : LET Map(42,5) = BLUE
LET Map(43,1) = 04 : LET Map(43,2) = 07                      : LET Map(43,4) = YELLOW  : LET Map(43,5) = BLACK
LET Map(44,1) = 04 : LET Map(44,2) = 06                      : LET Map(44,4) = WHITE   : LET Map(44,5) = RED
LET Map(45,1) = 03 : LET Map(45,2) = 06                      : LET Map(45,4) = WHITE   : LET Map(45,5) = RED
LET Map(46,1) = 02 : LET Map(46,2) = 06 : LET Map(46,3) = 1  : LET Map(46,4) = CYAN    : LET Map(46,5) = WHITE
LET Map(47,1) = 02 : LET Map(47,2) = 07                      : LET Map(47,4) = CYAN    : LET Map(47,5) = RED
LET Map(48,1) = 02 : LET Map(48,2) = 08 : LET Map(48,3) = -1 : LET Map(48,4) = BLACK   : LET Map(48,5) = YELLOW
LET Map(49,1) = 02 : LET Map(49,2) = 09                      : LET Map(49,4) = WHITE   : LET Map(49,5) = RED
LET Map(50,1) = 02 : LET Map(50,2) = 11                      : LET Map(50,4) = CYAN    : LET Map(50,5) = BLACK
LET Map(51,1) = 02 : LET Map(51,2) = 13                      : LET Map(51,4) = BLUE    : LET Map(51,5) = RED
LET Map(52,1) = 02 : LET Map(52,2) = 14                      : LET Map(52,4) = WHITE   : LET Map(52,5) = BLUE
LET Map(53,1) = 03 : LET Map(53,2) = 14                      : LET Map(53,4) = YELLOW  : LET Map(53,5) = RED
LET Map(54,1) = 04 : LET Map(54,2) = 14                      : LET Map(54,4) = BLUE    : LET Map(54,5) = WHITE
LET Map(55,1) = 04 : LET Map(55,2) = 13                      : LET Map(55,4) = WHITE   : LET Map(55,5) = BLUE
LET Map(56,1) = 04 : LET Map(56,2) = 12                      : LET Map(56,4) = BLUE    : LET Map(56,5) = RED
LET Map(57,1) = 04 : LET Map(57,2) = 11                      : LET Map(57,4) = BLUE    : LET Map(57,5) = WHITE
LET Map(58,1) = 04 : LET Map(58,2) = 10                      : LET Map(58,4) = WHITE   : LET Map(58,5) = BLUE
LET Map(59,1) = 05 : LET Map(59,2) = 10                      : LET Map(59,4) = WHITE   : LET Map(59,5) = BLUE
LET Map(60,1) = 06 : LET Map(60,2) = 10                      : LET Map(60,4) = RED     : LET Map(60,5) = GREEN
LET Map(61,1) = 07 : LET Map(61,2) = 10                      : LET Map(61,4) = WHITE   : LET Map(61,5) = BLUE 
LET Map(62,1) = 08 : LET Map(62,2) = 10                      : LET Map(62,4) = WHITE   : LET Map(62,5) = RED
LET Map(63,1) = 08 : LET Map(63,2) = 11                      : LET Map(63,4) = WHITE   : LET Map(63,5) = RED
LET Map(64,1) = 08 : LET Map(64,2) = 12 : LET Map(64,3) = -1 : LET Map(64,4) = WHITE   : LET Map(64,5) = RED
LET Map(65,1) = 08 : LET Map(65,2) = 13                      : LET Map(65,4) = WHITE   : LET Map(65,5) = RED
LET Map(66,1) = 08 : LET Map(66,2) = 14                      : LET Map(66,4) = WHITE   : LET Map(66,5) = BLUE
LET Map(67,1) = 07 : LET Map(67,2) = 14                      : LET Map(67,4) = WHITE   : LET Map(67,5) = RED
LET Map(68,1) = 06 : LET Map(68,2) = 14                      : LET Map(68,4) = WHITE   : LET Map(68,5) = RED
LET Map(69,1) = 06 : LET Map(69,2) = 13                      : LET Map(69,4) = WHITE   : LET Map(69,5) = BLUE
LET Map(70,1) = 06 : LET Map(70,2) = 12 : LET Map(70,3) = 1  : LET Map(70,4) = CYAN    : LET Map(70,5) = WHITE
LET Map(71,1) = 07 : LET Map(71,2) = 12                      : LET Map(71,4) = WHITE   : LET Map(71,5) = RED
LET Map(72,1) = 08 : LET Map(72,2) = 12 : LET Map(72,3) = -1 : LET Map(72,4) = WHITE   : LET Map(72,5) = RED
LET Map(73,1) = 09 : LET Map(73,2) = 12                      : LET Map(73,4) = BLUE    : LET Map(73,5) = YELLOW
LET Map(74,1) = 10 : LET Map(74,2) = 12                      : LET Map(74,4) = BLUE    : LET Map(74,5) = RED
LET Map(75,1) = 10 : LET Map(75,2) = 13                      : LET Map(75,4) = WHITE   : LET Map(75,5) = BLUE
LET Map(76,1) = 10 : LET Map(76,2) = 14 : LET Map(76,3) = -1 : LET Map(76,4) = MAGENTA : LET Map(76,5) = BLACK
LET Map(77,1) = 10 : LET Map(77,2) = 15                      : LET Map(77,4) = YELLOW  : LET Map(77,5) = BLACK
LET Map(78,1) = 10 : LET Map(78,2) = 16                      : LET Map(78,4) = WHITE   : LET Map(78,5) = RED
LET Map(79,1) = 09 : LET Map(79,2) = 16                      : LET Map(79,4) = BLUE    : LET Map(79,5) = WHITE
LET Map(80,1) = 08 : LET Map(80,2) = 16                      : LET Map(80,4) = WHITE   : LET Map(80,5) = RED
LET Map(81,1) = 07 : LET Map(81,2) = 16 : LET Map(81,3) = -1 : LET Map(81,4) = MAGENTA : LET Map(81,5) = BLACK
LET Map(82,1) = 06 : LET Map(82,2) = 16                      : LET Map(82,4) = BLUE    : LET Map(82,5) = WHITE
LET Map(83,1) = 05 : LET Map(83,2) = 16                      : LET Map(83,4) = CYAN    : LET Map(83,5) = MAGENTA
LET Map(84,1) = 04 : LET Map(84,2) = 16 : LET Map(84,3) = 1  : LET Map(84,4) = CYAN    : LET Map(84,5) = BLUE
LET Map(85,1) = 03 : LET Map(85,2) = 16                      : LET Map(85,4) = WHITE   : LET Map(85,5) = BLUE
LET Map(86,1) = 02 : LET Map(86,2) = 16                      : LET Map(86,4) = BLUE    : LET Map(86,5) = YELLOW
LET Map(87,1) = 01 : LET Map(87,2) = 16                      : LET Map(87,4) = GREEN   : LET Map(87,5) = BLUE
LET Map(88,1) = 00 : LET Map(88,2) = 16 : LET Map(88,3) = 1  : LET Map(88,4) = CYAN    : LET Map(88,5) = WHITE
LET Map(89,1) = 00 : LET Map(89,2) = 15                      : LET Map(89,4) = BLUE    : LET Map(89,5) = CYAN
LET Map(90,1) = 00 : LET Map(90,2) = 14                      : LET Map(90,4) = WHITE   : LET Map(90,5) = BLUE
LET Map(91,1) = 00 : LET Map(91,2) = 13                      : LET Map(91,4) = WHITE   : LET Map(91,5) = RED
LET Map(92,1) = 00 : LET Map(92,2) = 12                      : LET Map(92,4) = WHITE   : LET Map(92,5) = BLUE
LET Map(93,1) = 00 : LET Map(93,2) = 11                      : LET Map(93,4) = WHITE   : LET Map(93,5) = BLUE
LET Map(94,1) = 00 : LET Map(94,2) = 10 : LET Map(94,3) = 1  : LET Map(94,4) = CYAN    : LET Map(94,5) = RED
LET Map(95,1) = 00 : LET Map(95,2) = 9                       : LET Map(95,4) = GREEN   : LET Map(95,5) = BLACK
LET Map(96,1) = 00 : LET Map(96,2) = 8                       : LET Map(96,4) = WHITE   : LET Map(96,5) = BLUE
LET Map(97,1) = 00 : LET Map(97,2) = 7                       : LET Map(97,4) = WHITE   : LET Map(97,5) = RED
LET Map(98,1) = 00 : LET Map(98,2) = 6 : LET Map(98,3) = -1  : LET Map(98,4) = WHITE   : LET Map(98,5) = BLUE
LET Map(99,1) = 00 : LET Map(99,2) = 5                       : LET Map(99,4) = YELLOW  : LET Map(99,5) = BLUE
LET Map(100,1) = 0 : LET Map(100,2) = 3                      : LET Map(100,4) = CYAN   : LET Map(100,5) = BLACK
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE NextTurn
BEGIN
LET TurnPlayer = TurnPlayer + 1
IF (TurnPlayer > NumPlayers) THEN LET TurnPlayer = 1
END PROCEDURE

PROCEDURE StartComputerTurn
TapeForward(TurnPlayer)
PRINT AT 23,0; INK YELLOW;  "It's the computer's turn"; TAB 32;
END PROCEDURE

PROCEDURE StartHumanTurn
BEGIN
TapeForward(TurnPlayer)
PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); ", press "; TurnPlayer; " to play"; TAB 32;
REPEAT
  PAUSE 0
UNTIL INKEY = STR(TurnPlayer)
PRINT AT 23,0; " "; TAB 32;
BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
WaitNokey
END PROCEDURE

PROCEDURE StartTurn
BEGIN
IF (ComputerPlays AND TurnPlayer = 2)
  StartComputerTurn
ELSE
  StartHumanTurn
ENDIF
EraseDice
IF (UseImages) THEN EraseSprite(12,19)
WriteDescription
RestoreSprite
END PROCEDURE

FUNCTION PlayerIsLast TYPE BOOLEAN
VAR result TYPE BOOLEAN
VAR i TYPE UBYTE
BEGIN
LET result = TRUE
FOR i=1 TO NumPlayers
  IF (i <> TurnPlayer AND PlayerPositions(i) < PlayerPositions(TurnPlayer)) THEN LET result = FALSE
NEXT i
IF (result) THEN PlayerWaitAll(TurnPlayer) = FALSE
RETURN result
END FUNCTION

PROCEDURE Game
BEGIN
InitGame
ConfigPlayers
DrawScreen
REPEAT
  NextTurn
  IF (PlayerSkipTurns(TurnPlayer) > 0)
    PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); " skips a turn"; TAB 32;
    PAUSE 3*50
    PlayerSkipTurns(TurnPlayer) = PlayerSkipTurns(TurnPlayer) - 1
  ELSEIF (PlayerWaitAll(TurnPlayer) AND NOT PlayerIsLast)
    PRINT AT 23,0; INK YELLOW; PlayerNames(TurnPlayer); " is waiting for all"; TAB 32;
    PAUSE 3*50
  ELSE
    PlacePlayers
    StartTurn
    RollDice
    MovePlayer
  ENDIF
UNTIL (PlayerPositions(TurnPlayer) >= 100)
PlacePlayers
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE Introduction
VAR key$ TYPE STRING
BEGIN
BORDER BLACK : PAPER BLACK : INK GREEN : CLS
WriteLine("This video game is based on ""Jogo do Transito"" (Road Safety Game) sponsored by Shell.")
PRINT
WriteLine("The game was distributed during Christmas 1954 in Portugal, inside a comic book.")
PRINT
INK CYAN
WriteLine("\* 2024 by StarSoft")
INK YELLOW
PRINT AT 16,0; "This program loads images from","tape."
PRINT "It is advisable to run it on the QAOP emulator - other emulators may not be fast enough."
PRINT "Options:"
PRINT " "; PAPER GREEN; INK BLACK; "0"; PAPER BLACK; INK WHITE; " - run without images"
PRINT " "; PAPER GREEN; INK BLACK; "1"; PAPER BLACK; INK WHITE; " - run with images"
REPEAT
  PAUSE 1
  PAUSE 0
  key$ = INKEY$
UNTIL (key$ = "0" OR key$ = "1" )
BEEP .01,0: BEEP .02,10: BEEP .08,20: BEEP .01,30
IF key$ = "0" THEN UseImages = FALSE ELSE UseImages = TRUE 
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE Credits
BEGIN
BORDER WHITE : PAPER WHITE : INK BLACK : CLS
PRINT "The Shell Road Safety Game"
PRINT "Written by David Magalhaes"
PRINT "Language: Pascalated BASIC"
PRINT "(c)2024 by Starsoft"
PRINT
PRINT "Tools:"
PRINT "Visual Studio Code (text editor)";: REM blank line
PRINT "ZX BASIC (Boriel) (compiler)"
PRINT "BASinC (tape editor)"
PRINT "PSP6 (image processor)"
PRINT "BMP2SCR (png to tape)"
PAUSE 50 : PAUSE 0
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE TestColors
VAR square TYPE UBYTE
BEGIN
FOR square = 0 TO 99
  PAPER BLACK : INK WHITE
  PRINT AT 0,0; square;
  LoadSprite(square)
  PAPER Map(square,4)
  INK Map(square,5)
  ShowSprite(12,19)
  PAUSE 50 : PAUSE 0
NEXT square
END PROCEDURE

'--------------------------------------------------------------

PROCEDURE MainRoutine
VAR key TYPE STRING
BEGIN
InitProgram
'TestColors
Introduction
REPEAT
  Game
  PRINT AT 23,0; TAB 32;
  PRINT AT 22,0; INK MAGENTA; "Play Again? ";
  REPEAT
    key = INKEY
  UNTIL key = "y" OR key = "Y" OR key = "n" OR key = "N"  
UNTIL key = "n" OR key = "N" 
Credits
PAUSE 5*50
END PROCEDURE

'--------------------------------------------------------------

BEGIN PROGRAM Road Safety
MainRoutine
END PROGRAM
